#ifndef _ROMLOADER_H_
#define _ROMLOADER_H_

// State is non-zero if found. 1 = found totally okay
enum FIND_STATE {
	STAT_NOFIND = 0,
	STAT_OK,
	STAT_CRC,
	STAT_SMALL,
	STAT_LARGE,
};

// RomLoader class, added by regret
class RomLoader : public IRomLoader {
public:
	enum RomLoader_Status {
		RL_STATUS_OK = 0,
		RL_STATUS_BADDATA,
		RL_STATUS_ERROR
	};

	virtual int loadRom(unsigned char* dest, unsigned* wrote, unsigned i);
	virtual int loadOneRom(const char* arcName, const char* fileName, void** dest, unsigned* wrote);

	int status();
	void switchInterface();
	int check();
	int open();
	int close();

	RomLoader();
	virtual ~RomLoader();

protected:
	virtual int burnLoadRom(unsigned char* dest, unsigned* wrote, unsigned i);
	virtual int burnerLoadRom(unsigned char* dest, unsigned* wrote, unsigned i);

private:
	struct ROMFIND {
		FIND_STATE state;
		int archive;
		int pos;
	};

	int archiveError;				// non-zero if there is a problem with the opened romset
	wchar_t* archiveName[BZIP_MAX];	// Archive files to search through
	ROMFIND* romFind;
	int romCount;
	int totalSize;

	ArcEntry* arcList;
	unsigned listCount;				// arcList of entries for current archive file
	int currentArc; 				// Archive which is currently open
	bool burnInterfaceFlag;			// false indicate use normal function

	void clearArchiveList();
	int romDescribe(BurnRomInfo* pri);
	int getError(int state);
	int checkInternal();
};

extern RomLoader romLoader;

#endif
